"""
Image Transformations for Inference.
    No boxes and labels as inputs.
"""
from PIL import Image


class ImageResize(object):
    def __init__(self, size, interpolation=Image.BILINEAR):
        self.size = size
        self.interpolation = interpolation
    
    def __call__(self, image):
        image = image.resize(self.size, self.interpolation)
        return image


# temporary transformation for pretrained model inference.
class ImageToTensor(object):
    """
    convert PIL.Image to tensor
    """
    def __init__(self, image_size):
        self.image_size = image_size

    def __call__(self, image):
        image = np.array(image)
        image = cv2.resize(image, (self.image_size[0], self.image_size[1]), 
                           interpolation=cv2.INTER_LINEAR)
        image = image.astype(np.float32)
        image = image / 255.0
        image = np.transpose(image, (2, 0, 1))
        image = torch.from_numpy(image)
        return image
